package cloud.study.template.config;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;

/**
 * @author : forget.liu@aliyun.com
 * @date : 2020/3/24 13:12
 * @description : TODO
 */
@Configuration
@EnableAsync
public class AsyncPoolConfigurer implements AsyncConfigurer {
    /**
     * 配置异步多线程
     *
     * @return 异步处理线程池
     */
    @Override
    public Executor getAsyncExecutor() {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNamePrefix("AsyncPool--").build();
        return new ThreadPoolExecutor(6, 36,
                1000L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
    }
}
